using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ObjectLib;

namespace ObjectParser
{
	/// <summary>
	/// Summary description for ObjPropertiesDialog.
	/// </summary>
	public class ObjPropertiesDialog : System.Windows.Forms.Form
	{
		private System.Windows.Forms.RichTextBox rtbText;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button butOK;
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox textOccluded;
		private System.Windows.Forms.TextBox textShadow;
		private System.Windows.Forms.TextBox textDeadLiving;
		private System.Windows.Forms.TextBox textRoughSmooth;
		private System.Windows.Forms.TextBox textSpecularized;
		private System.Windows.Forms.TextBox textUniformVariegated;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox textFocus;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.TextBox textQuality;
		public ParsedObject Pobj;

		public ObjPropertiesDialog(ParsedObject Pobj)
		{
			InitializeComponent();

			this.Pobj = Pobj;
			this.textQuality.Text = Convert.ToString(Pobj.CatData.Quality);
			this.textFocus.Text = Convert.ToString(Pobj.CatData.Focused);
			this.textSpecularized.Text = Convert.ToString(Pobj.CatData.Specularized);
			this.textUniformVariegated.Text = Convert.ToString(Pobj.CatData.UniformToVariegated);
			this.textOccluded.Text = Convert.ToString(Pobj.CatData.Occluded);
			this.textDeadLiving.Text = Convert.ToString(Pobj.CatData.DeadToLiving);
            this.textRoughSmooth.Text = Convert.ToString(Pobj.CatData.SmoothToRough);
			this.textShadow.Text = Convert.ToString(Pobj.CatData.SharpShadowBoundary);
			this.rtbText.Text = Pobj.SearchText;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.rtbText = new System.Windows.Forms.RichTextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.butOK = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.textOccluded = new System.Windows.Forms.TextBox();
			this.textShadow = new System.Windows.Forms.TextBox();
			this.textDeadLiving = new System.Windows.Forms.TextBox();
			this.textRoughSmooth = new System.Windows.Forms.TextBox();
			this.textSpecularized = new System.Windows.Forms.TextBox();
			this.textUniformVariegated = new System.Windows.Forms.TextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.textFocus = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.textQuality = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// rtbText
			// 
			this.rtbText.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.rtbText.Location = new System.Drawing.Point(8, 400);
			this.rtbText.Name = "rtbText";
			this.rtbText.Size = new System.Drawing.Size(296, 104);
			this.rtbText.TabIndex = 0;
			this.rtbText.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 368);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(144, 24);
			this.label1.TabIndex = 1;
			this.label1.Text = "Search Text:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			// 
			// butOK
			// 
			this.butOK.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.butOK.Location = new System.Drawing.Point(8, 512);
			this.butOK.Name = "butOK";
			this.butOK.Size = new System.Drawing.Size(296, 23);
			this.butOK.TabIndex = 2;
			this.butOK.Text = "OK";
			this.butOK.Click += new System.EventHandler(this.butOK_Click);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 304);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(216, 16);
			this.label2.TabIndex = 3;
			this.label2.Text = "Specularized (1 to 5):";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(0, 336);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(224, 23);
			this.label3.TabIndex = 4;
			this.label3.Text = "Uniform (1) to Variegated (5):";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(0, 72);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(224, 23);
			this.label4.TabIndex = 5;
			this.label4.Text = "Occluded (1 or 2):";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 240);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(216, 23);
			this.label5.TabIndex = 6;
			this.label5.Text = "Dead (1) to Living (5):";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(0, 272);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(224, 24);
			this.label6.TabIndex = 7;
			this.label6.Text = "Surface Roughness (1) to Smoothness (5):";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(0, 104);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(224, 23);
			this.label7.TabIndex = 8;
			this.label7.Text = "Sharp shadow boundary (1 or 2):";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label8
			// 
			this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label8.Location = new System.Drawing.Point(0, 200);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(144, 24);
			this.label8.TabIndex = 9;
			this.label8.Text = "Integers (1 to 5):";
			this.label8.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			// 
			// label9
			// 
			this.label9.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label9.Location = new System.Drawing.Point(8, 8);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(144, 24);
			this.label9.TabIndex = 10;
			this.label9.Text = "Integers (1 or 2):";
			this.label9.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			// 
			// textOccluded
			// 
			this.textOccluded.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textOccluded.Location = new System.Drawing.Point(224, 72);
			this.textOccluded.Name = "textOccluded";
			this.textOccluded.Size = new System.Drawing.Size(80, 20);
			this.textOccluded.TabIndex = 11;
			this.textOccluded.Text = "";
			// 
			// textShadow
			// 
			this.textShadow.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textShadow.Location = new System.Drawing.Point(224, 104);
			this.textShadow.Name = "textShadow";
			this.textShadow.Size = new System.Drawing.Size(80, 20);
			this.textShadow.TabIndex = 12;
			this.textShadow.Text = "";
			// 
			// textDeadLiving
			// 
			this.textDeadLiving.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textDeadLiving.Location = new System.Drawing.Point(224, 240);
			this.textDeadLiving.Name = "textDeadLiving";
			this.textDeadLiving.Size = new System.Drawing.Size(80, 20);
			this.textDeadLiving.TabIndex = 13;
			this.textDeadLiving.Text = "";
			// 
			// textRoughSmooth
			// 
			this.textRoughSmooth.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textRoughSmooth.Location = new System.Drawing.Point(224, 272);
			this.textRoughSmooth.Name = "textRoughSmooth";
			this.textRoughSmooth.Size = new System.Drawing.Size(80, 20);
			this.textRoughSmooth.TabIndex = 14;
			this.textRoughSmooth.Text = "";
			// 
			// textSpecularized
			// 
			this.textSpecularized.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textSpecularized.Location = new System.Drawing.Point(224, 304);
			this.textSpecularized.Name = "textSpecularized";
			this.textSpecularized.Size = new System.Drawing.Size(80, 20);
			this.textSpecularized.TabIndex = 15;
			this.textSpecularized.Text = "";
			// 
			// textUniformVariegated
			// 
			this.textUniformVariegated.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textUniformVariegated.Location = new System.Drawing.Point(224, 336);
			this.textUniformVariegated.Name = "textUniformVariegated";
			this.textUniformVariegated.Size = new System.Drawing.Size(80, 20);
			this.textUniformVariegated.TabIndex = 16;
			this.textUniformVariegated.Text = "";
			// 
			// label10
			// 
			this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label10.Location = new System.Drawing.Point(0, 136);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(144, 24);
			this.label10.TabIndex = 17;
			this.label10.Text = "Integers (1 to 3):";
			this.label10.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(0, 168);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(224, 23);
			this.label11.TabIndex = 18;
			this.label11.Text = "Unfocused (1) to Focused (3):";
			this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textFocus
			// 
			this.textFocus.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textFocus.Location = new System.Drawing.Point(224, 168);
			this.textFocus.Name = "textFocus";
			this.textFocus.Size = new System.Drawing.Size(80, 20);
			this.textFocus.TabIndex = 19;
			this.textFocus.Text = "";
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(0, 40);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(224, 23);
			this.label12.TabIndex = 20;
			this.label12.Text = "Bad (1) or Good (2) Quality:";
			this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textQuality
			// 
			this.textQuality.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textQuality.Location = new System.Drawing.Point(224, 40);
			this.textQuality.Name = "textQuality";
			this.textQuality.Size = new System.Drawing.Size(80, 20);
			this.textQuality.TabIndex = 21;
			this.textQuality.Text = "";
			// 
			// ObjPropertiesDialog
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(312, 542);
			this.Controls.Add(this.textQuality);
			this.Controls.Add(this.label12);
			this.Controls.Add(this.textFocus);
			this.Controls.Add(this.label11);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.textUniformVariegated);
			this.Controls.Add(this.textSpecularized);
			this.Controls.Add(this.textRoughSmooth);
			this.Controls.Add(this.textDeadLiving);
			this.Controls.Add(this.textShadow);
			this.Controls.Add(this.textOccluded);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.butOK);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.rtbText);
			this.Name = "ObjPropertiesDialog";
			this.Text = "Object Properties";
			this.ResumeLayout(false);

		}
		#endregion
		private void butOK_Click(object sender, System.EventArgs e)
		{
			bool proceed = true;

			int spec=Pobj.CatData.Specularized;
			int unif=Pobj.CatData.UniformToVariegated;
			int occ = Pobj.CatData.Occluded;
			int dead = Pobj.CatData.DeadToLiving;
            int rough= Pobj.CatData.SmoothToRough;
			int shadow = Pobj.CatData.SharpShadowBoundary;
			int qual = Pobj.CatData.Quality;
			int foc = Pobj.CatData.Focused;

			try{	spec = Convert.ToInt32(this.textSpecularized.Text); }
			catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textSpecularized.Focus(); }

			if(proceed)
			{
				try{	qual = Convert.ToInt32(this.textQuality.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textQuality.Focus(); }
			}

			if(proceed)
			{
				try{	foc = Convert.ToInt32(this.textFocus.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textFocus.Focus(); }
			}

			if(proceed)
			{
				try{	unif = Convert.ToInt32(this.textUniformVariegated.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textUniformVariegated.Focus(); }
			}
			if(proceed)
			{
				try{	occ = Convert.ToInt32(this.textOccluded.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textOccluded.Focus(); }
			}
			if(proceed)
			{
				try{	dead = Convert.ToInt32(this.textDeadLiving.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textDeadLiving.Focus(); }
			}
			if(proceed)
			{
				try{	rough = Convert.ToInt32(this.textRoughSmooth.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textRoughSmooth.Focus(); }
			}
			if(proceed)
			{
				try{	shadow = Convert.ToInt32(this.textShadow.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textShadow.Focus(); }
			}
			if(proceed)
			{
				if( spec<0 || spec>ObjectCategorizationData._Specularized  )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be between 0 and " + Convert.ToString(ObjectCategorizationData._Specularized));
					this.textSpecularized.Focus();
				}
			}
			if(proceed)
			{
				if( unif<0 ||  unif>ObjectCategorizationData._UniformToVariegated )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be between 0 and " + Convert.ToString(ObjectCategorizationData._UniformToVariegated));
					this.textUniformVariegated.Focus();
				}
			}
			if(proceed)
			{
				if( occ<0 || occ>ObjectCategorizationData._Occluded )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be between 0 and " + Convert.ToString(ObjectCategorizationData._Occluded));
					this.textOccluded.Focus();
				}
			}
			if(proceed)
			{
				if( dead<0 || dead>ObjectCategorizationData._DeadToLiving )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be between 0 and " + Convert.ToString(ObjectCategorizationData._DeadToLiving));
					this.textDeadLiving.Focus();
				}
			}
			if(proceed)
			{
                if(rough<0 || rough>ObjectCategorizationData._SmoothToRough)
				{
					proceed = false;
                    MessageBox.Show(this,"Value must be between 0 and " + Convert.ToString(ObjectCategorizationData._SmoothToRough));
					this.textRoughSmooth.Focus();
				}
			}
			if(proceed)
			{
				if( shadow<0 || shadow>ObjectCategorizationData._SharpShadowBoundary )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be between 0 and " + Convert.ToString(ObjectCategorizationData._SharpShadowBoundary));
					this.textShadow.Focus();
				}
			}
			if(proceed)
			{
				Pobj.SearchText = this.rtbText.Text;
				Pobj.CatData.Quality = qual;
				Pobj.CatData.Focused = foc;
				Pobj.CatData.Specularized = spec;
				Pobj.CatData.UniformToVariegated = unif;
				Pobj.CatData.Occluded = occ;
				Pobj.CatData.DeadToLiving = dead;
                Pobj.CatData.SmoothToRough = rough;
				Pobj.CatData.SharpShadowBoundary = shadow;

				this.DialogResult = DialogResult.OK;
				this.Close();
			}
			else
				this.DialogResult = DialogResult.Cancel;
		}
	}
}